import React, { Component } from "react";

export default class App extends Component {
    state = {
        firstName: '1',
        lastName: '2'
    }

    changeFirstName = (event) => {
        this.setState({
            firstName: event.target.value
        })
    }
    changeLastName = (event) => {
        this.setState({
            lastName: event.target.value
        })
    }

    render() {
        return (
            <div>
                {/* 通过input的change事件改变 */}
                <input type="text" value={this.state.firstName} onChange={this.changeFirstName} /> +
                <input type="text" value={this.state.lastName} onChange={this.changeLastName} /> =
                {Number(this.state.firstName) + Number(this.state.lastName)}
            </div>
        )
    }
}